import dt from '@dt/dt'
import userApi from '@/config/server/api/user'
import buildingApi from '@/config/server/api/building'
import baseApi from '@/config/server/api/base'
import userMgr from '@/biz/user'

let key_buildInfo = 'build_info'
let buildInfo = dt.session.get(key_buildInfo)

function updateBuildInfo(res) {
  dt.session.set(key_buildInfo, res)
  buildInfo = res
}

function info() {
  return buildInfo
}
dt.buildInfo = info

// 归属顾问
function counselors(params) {
  return userApi.counselorList
    .fetch({
      ...params,
      userId: dt.userInfo().userId
    })
    .then((res) => {
      return res
    })
}

// 案场列表-根据输入案场名称模糊搜索
function buildsForName(housesName) {
  return buildingApi.caseList.getHousesNames
    .fetch({
      housesName
    })
    .then((res) => {
      return res.list
    })
}

//楼盘附件
function houseAnnexList(info) {
  return buildingApi.house.houseAnnexList.fetch(info)
}
// 相册图片新增
function getPhotoAdd(info) {
  info.createrId = userMgr.info().userId
  return buildingApi.house.getPhotoAdd.fetch(info)
}
// 相册图片删除
function getPhotoDelete(info) {
  info.updaterId = userMgr.info().userId
  return buildingApi.house.getPhotoDelete.fetch(info)
}
// 相册图片编辑
function getPhotoUpdate(info) {
  info.updaterId = userMgr.info().userId
  return buildingApi.house.getPhotoUpdate.fetch(info)
}

function getAreacodePropertyList(info) {
  // info.updaterId = userMgr.info().userId
  return baseApi.generalConfiguration.cityList().fetch(info)
}

function getStreetList(info) {
  // info.updaterId = userMgr.info().userId
  return baseApi.generalConfiguration.areaPages.fetch(info)
}

function getLoopInfo(info) {
  return baseApi.generalConfiguration.loopPages.fetch(info)
}

function mettroHlist(info) {
  return baseApi.generalConfiguration.mettroHlist.fetch(info)
}

function getStoriedList(info) {
  return buildingApi.house.getStoriedList.fetch(info)
}

function getStoriedAdd(info) {
  info.createrId = userMgr.info().userId
  return buildingApi.house.getStoriedAdd.fetch(info)
}

function getStoriedUpdate(info) {
  info.updaterId = userMgr.info().userId
  return buildingApi.house.getStoriedUpdate.fetch(info)
}

function getStoriedDelete(info) {
  info.updaterId = userMgr.info().userId
  return buildingApi.house.getStoriedDelete.fetch(info)
}

function getUnitList(info) {
  return buildingApi.house.getUnitList.fetch(info)
}

function getHouseTypeList(info) {
  return buildingApi.housetype.getHouseTypeList.fetch(info)
}

function selectBuHousesInfo(info) {
  return buildingApi.house.selectBuHousesInfo.fetch(info)
}

function selectAuditBuHousesInfo(info) {
  return buildingApi.house.selectAuditBuHousesInfo.fetch(info)
}

function updateBuHousesInfo(info) {
  return buildingApi.house.updateBuHousesInfo.fetch(info)
}

function housesSubmit(info) {
  return buildingApi.house.housesSubmit.fetch(info)
}

function operateLogProperty(info) {
  return buildingApi.house.operateLogProperty.fetch(info)
}

function LogList(info) {
  return buildingApi.house.LogList.fetch(info)
}

function housesAudit(info) {
  return buildingApi.house.housesAudit.fetch(info)
}

function updateBuHousesInfoShowFlag(info) {
  return buildingApi.house.updateBuHousesInfoShowFlag.fetch(info)
}
export default {
  updateBuildInfo,
  info,
  counselors,
  buildsForName,
  houseAnnexList,
  getPhotoAdd,
  getPhotoDelete,
  getPhotoUpdate,

  // 城市级联
  getAreacodePropertyList,
  getStreetList,
  getLoopInfo,
  mettroHlist,
  // 楼栋
  getStoriedList,
  getStoriedAdd,
  getStoriedUpdate,
  getStoriedDelete,
  getUnitList,
  getHouseTypeList,

  selectBuHousesInfo,
  selectAuditBuHousesInfo,
  updateBuHousesInfo,
  housesSubmit,
  LogList,
  operateLogProperty,
  housesAudit,
  updateBuHousesInfoShowFlag
}
